package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eRechargeGainIndex;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.recharge.RechargeGainModule;
import com.yanqu.road.server.manger.recharge.RechargeMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.Map;

/**
 * 第三方元宝充值首充双倍
 */
public class IngotsRechargeThirdDouble extends BaseRecharge {

    public IngotsRechargeThirdDouble(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        return false;
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        Property resultProp = PropertyHelper.parseStringToProperty(mallInfo.getReward());
        if(mallInfo.isFirstDouble()){
            RechargeGainModule rechargeGainModule = player.getModule(RechargeGainModule.class);
            if(RechargeMgr.isUseNewMultiple()) {
                rechargeGainModule.handleRechargeMultiple(mallInfo, resultProp, eRechargeGainIndex.ThirdPartyFirstDouble.getValue());
            }else {
                //判断首充翻倍
                if (rechargeGainModule.isFirstRechargeDouble(mallInfo, eRechargeGainIndex.ThirdPartyFirstDouble.getValue())) {
                    for(Map.Entry<Integer, BigInteger> dataEntry : resultProp.getGoods().entrySet()){
                        dataEntry.setValue(dataEntry.getValue().multiply(BigInteger.valueOf(2)));
                    }
                    rechargeGainModule.changeRechargeGain(mallInfo.getMallId(), eRechargeGainIndex.ThirdPartyFirstDouble.getValue());
                }
            }

        }
        player.getModule(CurrencyModule.class).addCurrency(resultProp, eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
        String rewardStr = PropertyHelper.parsePropertyToString(resultProp);
        logger.info("订单: {}, 商品: {}, 充值元宝: {}", orderNo, mallInfo.getMallId(), rewardStr);
        return rewardStr;
    }
}
